#ifndef M_WAVE_H
#define M_WAVE_H

#include "Huffman.h"

typedef struct DataLocationStructure {

#ifdef WINDOWS_MAKE /* for windows compile */
	void *ptr;
#else /* for embeded compile*/
	void *ptr;
#endif

	long size;
} DataLocation;

typedef struct WaveHeaderStructure {
	//int nSamples;
	int vSampleRates;
	short nChannels;
	short vBps;
	short HTP; // Huffman Tree Pointer
	HuffmanTree* pTree;
	short ETP; // Entry Table Pointer
	short DEP; // Data Entry Pointer
} WaveHeader;

typedef struct WaveDataStructure {
	unsigned char* data;
	long DEP; // N-th Data Entry Point ( global DEP + N-th DEP offset )
	long size;
} WaveData;

typedef enum WaveFormatEnum {
	RAW,
	HUFFMAN,
	DIFFHUFFMAN,
	DIFFHUFFMANSERIES
} WaveFormat;

#ifdef WINDOWS_MAKE

DataLocation LoadIntoRAM(const char* filename);
void SaveIntoDrive(DataLocation loc, const char* filename);

void WriteWaveHeader(DataLocation* loc, WaveHeader wavhdr);
void WriteHuffmanTree(DataLocation* loc, WaveHeader* wavhdr, HuffmanTree huffs);
void WriteWaveData(DataLocation* loc, WaveHeader* wavhdr, WaveData wavdat);

#endif

WaveHeader ReadWaveHeader(DataLocation loc);
void ReadHuffmanTree(DataLocation loc, WaveHeader wavhdr);
WaveData ReadWaveData(DataLocation loc, WaveHeader wavhdr, int nth);
void LoadWaveData(DataLocation loc, WaveHeader wavhdr, int nth, unsigned char* buf, int buf_size);

#endif